package com.itheima.info.manager.service;

import com.itheima.info.manager.domain.Teacher;
import com.itheima.info.manager.dao.TeacherDao;

public class TeacherService {
    TeacherDao teacherDao = new TeacherDao();
    Teacher[] teachers =teacherDao.findAllTeacher();

    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    public boolean isExists(String id) {
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teachers[i].getId().equals(id)){
                return true;
            }
        }
        return false;
    }

    public Teacher[] findAllTeacher() {
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i] != null) {
                flag = true;
                break;
            }
        }
        if (flag){
            return teachers;
        }else {
            return null;
        }
    }

    public boolean deleteTeacher(String id) {
        return teacherDao.deleteTeacher(id);
    }

    public boolean updateTeacher(Teacher teacher) {
        return teacherDao.updateTeacher(teacher);
    }
}
